package com.blrs.web.oss;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.CreateBucketRequest;

public class createBucket {
    public static String ACCESS_KEY = "DJX5UL3X31X4DTTDXI49";
    public static String SECRET_KEY = "AsKdVLPwHzChbN515kxXTBch9SntWcVjxSTr6bdc";
    public static String END_POINT = "https://changsha42.zos.ctyun.cn";
    public static String Bucket = "test2024-12-11";
    public static void main(String[] args) {
        AmazonS3 s3Client = null;
        try {
            AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY,
                    SECRET_KEY);
            ClientConfiguration awsClientConfig = new ClientConfiguration();
            awsClientConfig.setSignerOverride("AWSS3V4SignerType");
            awsClientConfig.setProtocol(Protocol.HTTP);
            s3Client = AmazonS3ClientBuilder.standard()
                    .withCredentials(new
                            AWSStaticCredentialsProvider(credentials))
                    .withClientConfiguration(awsClientConfig)
                    .withEndpointConfiguration(new
                            AwsClientBuilder.EndpointConfiguration(END_POINT, ""))
                    .disableChunkedEncoding()
                    .enablePathStyleAccess()
                    .build();
            System.out.print("=====connect success=====\n");
//创建Bucket
            CreateBucketRequest var = new CreateBucketRequest(Bucket);
            com.amazonaws.services.s3.model.Bucket bucket = s3Client.createBucket(var);
            System.out.println(bucket.getName());
            System.out.println("=====request success=====\n");
        }catch (Exception e) {
            System.out.println("=====request fail=====\n");
            System.out.println(e.getMessage());
        }
    }
}